/*
 * Copyright (c) 2017 Qunar.com. All Rights Reserved.
 */
package com.guoyu.project.web.api;

import com.google.common.collect.Maps;
import com.guoyu.project.common.pagination.Pagination;
import com.guoyu.project.model.Article;
import com.guoyu.project.model.Banner;
import com.guoyu.project.model.enums.ArticleType;
import com.guoyu.project.model.enums.ProjectType;
import com.guoyu.project.service.ArticleService;
import com.guoyu.project.service.BannerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.guoyu.project.common.web.APIResponse;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author: libo Date: 17-6-28 Time: 上午9:39
 * @version: \$Id$
 */
@Controller
@RequestMapping("api")
public class IndexApiController {

    @Resource
    private BannerService bannerService;

    @Resource
    private ArticleService articleService;

    @RequestMapping("index")
    @ResponseBody
    public APIResponse index() {
        List<Banner> bannerList = bannerService.queryBanners(null);

        Map<String, Object> params = Maps.newHashMap();
        params.put("majorType", ArticleType.NEWS);
        params.put("displayHome", Boolean.TRUE);
        List<Article> newsList = articleService.queryArticles(params);

        params.put("majorType", ArticleType.ANLI);
        List<Article> anliList = articleService.queryArticles(params);

        params.put("majorType", ArticleType.PROJECT);
//        params.put("minorType", ProjectType.PROJECT);
        List<Article> projectList = articleService.queryArticles(params);

        Map<String, Object> resultMap = Maps.newHashMap();
        resultMap.put("bannerList", bannerList);
        resultMap.put("newsList", newsList);
        resultMap.put("anliList", anliList);
        resultMap.put("projectList", projectList);
        return APIResponse.returnSuccess(resultMap);

    }
}
